//
//  BDPostModel.m
//  GetWebText
//
//  Created by wen on 2017/8/30.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDPostModel.h"

@implementation BDPostModel

+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"repostCount":@"statistic.repost",
             @"commentCount":@"statistic.comment",
             @"praiseCount":@"statistic.praise",
             @"sharedCount":@"statistic.shared",
             @"reportCount":@"statistic.report",
             @"my_id":@"id"};
}

- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
    if (dic[@"user"]) {
        self.user = [BDUserModel mj_objectWithKeyValues:dic[@"user"]];
    }
    else {
        self.user = [[BDUserModel alloc] init];
        self.user.user_id = [dic[@"user_id"] integerValue];
        self.user.cover = dic[@"cover"];
        self.user.vip_level = [dic[@"vip_level"] integerValue];
        self.user.nickname = dic[@"nickname"];
    }
    return YES;
}

//这是决定是购买了，还是没有购买，前提是肯定不免费的才会有这样的判断
- (BOOL)isPurchase{
    //首先应该判断哪一部分收费，然后判断这一部分是
    BDUserModel *user = [BDUserModel getCurrentUser];
    if (user.vip_level != 0 || user.is_admin == YES) {
        return YES;
    }else if (self.user.user_id == user.user_id){
        return YES;
    }else {
        if (self.user.user_id == user.user_id || self.price == 0 || self.purchase.count != 0) {
            return YES;
        }else if (self.repost.user.user_id == user.user_id || self.repost.price == 0 || self.repost_purchase.count != 0) {
            return YES;
        }
    }
    return NO;
}
@end
